                                                                                                                                                                                                                                                                                                                                              //
//  UserManager.m
//  星道教育
//
//  Created by xingdao on 15/11/14.
//  Copyright © 2015年 xingdao. All rights reserved.
//

#import "UserManager.h"
#import <Foundation/Foundation.h>
@implementation UserManager
+ (UserManager *)modelManager
{
    static dispatch_once_t once;
    static id instance;
    dispatch_once(&once, ^{
        instance = [self new];
    });
    return instance;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        _dic = [[NSDictionary alloc] init];
        _dates = [[NSArray alloc] init];
        _uid = [[NSString alloc] init];
        _modelArrs = [[NSMutableArray alloc] init];
        _rolecode = [[NSString alloc] init];
        _formate = [[NSString alloc] init];
        _flowers = [[NSString alloc] init];
        _invite_uid=[[NSString alloc] init];
        _avatar=[[NSString alloc] init];
        _authCode=[[NSString alloc] init];
        _UID = [[NSString alloc] init];
        _pwd=[[NSString alloc] init];
        _petName=[[NSString alloc] init];
        _dldic=[[NSMutableDictionary alloc] init];
        _myName = [[NSString alloc] init];
        _telephone = [[NSString alloc] init];
        _password = [[NSString alloc] init];
  
        //_chatStyle = [[NSString alloc] init];
        _myQid = [[NSString alloc] init];
        _isConnected = [[NSString alloc] init];
        _nameType = [[NSString alloc] init];
        _topicid = [[NSString alloc] init];
        _tableName = [[NSString alloc] init];
        
        _jiemianName = [[NSString alloc] init];
        
        _defiDic = [[NSDictionary alloc] init];
        _arrDatas = [[NSMutableArray alloc] init];
        _allDatasDic = [[NSMutableDictionary alloc] init];
        _jieShouDatas = [[NSMutableArray alloc] init];
        _tableNameDiff = [[NSString alloc] init];
        _kidUid = [[NSString alloc] init];
    }
    return self;
}
- (void)getThePersonDatas:(NSDictionary *)dic
{
  
  
    
 
    
    NSLog(@"%@",dic);

    NSString *uid = [dic valueForKey:@"uid"];
    NSString *rolecode = [dic valueForKey:@"rolecode"];
    
    NSString *invite_uid = [dic valueForKey:@"invite_uid"];
    
    NSString *avatar= [dic valueForKey:@"avatar"];
    
    
    self.uid = [NSString stringWithFormat:@"%@",uid];
    self.rolecode = [NSString stringWithFormat:@"%@",rolecode];
    self.flowers =[NSString stringWithFormat:@"%@",[dic valueForKey:@"flowers"]];
    self.myName = [dic valueForKey:@"petName"];
    self.invite_uid =[NSString stringWithFormat:@"%@",invite_uid];
    self.avatar =[NSString stringWithFormat:@"%@",avatar];
    self.telephone =[NSString stringWithFormat:@"%@",  [dic valueForKey:@"phone"]];
    self.password =[NSString stringWithFormat:@"%@",[dic valueForKey:@"password"]];
   
    
    
}



+ (void)parentSeleted:(NSString *)titl VC:(UIViewController *)vc andWho:(NSString *)name andTheMessage:(NSString *)message
{
    NSString *content;
    NSString *idString;
  
    NSRange rangID = [titl rangeOfString:@",id:"];
        if (rangID.length != 0) {
            content = [titl substringToIndex:rangID.location];

           idString = [titl substringFromIndex:rangID.location + rangID.length];
           
            //dic = [[NSDictionary alloc] initWithObjectsAndKeys:idString,@"idString",content,@"content", nil];
        }
    else
    {
        content = titl;
    }

    NSString *title = NSLocalizedString(content, nil);
    NSString *cancelButtonTitle;
    NSString *otherButtonTitle;
    if ([name isEqualToString:@"parent"]) {
   cancelButtonTitle = NSLocalizedString(klocalizeString(localDisagree), nil);
   otherButtonTitle = NSLocalizedString(klocalizeString(localAgree), nil);
    }
    else
    {
        cancelButtonTitle = NSLocalizedString(klocalizeString(cancel), nil);
        otherButtonTitle = NSLocalizedString(klocalizeString(sure), nil);
    }
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        if ([name isEqualToString:@"parent"]) {
            NSRange range = [content rangeOfString:@"请求访问版块:"];
            NSString *str;
            if (range.length != 0) {
                str = [content substringFromIndex:range.length+range.location];
            }

            NSDictionary *dic3 = [[NSDictionary alloc] initWithObjectsAndKeys:str,@"panelName",idString,@"idString", nil];
       
             [[NSNotificationCenter defaultCenter] postNotificationName:@"agree" object:@"1" userInfo:dic3];
        }
       
        
    }];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
  
        NSRange range = [content rangeOfString:@"请求访问版块:"];

        NSString *str;
        if (range.length != 0) {
            str = [content substringFromIndex:range.length + range.location];
        }
      
    
        NSDictionary *dic4 = [[NSDictionary alloc] initWithObjectsAndKeys:str,@"panelName",idString,@"idString", nil];
     
        if ([name isEqualToString:@"parent"]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"agree" object:@"0" userInfo:dic4];
        }
    }];
    if ([name isEqualToString:@"parent"]) {
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    }
    else
    {
       [alertController addAction:otherAction]; 
    }
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        
        alertController.popoverPresentationController.sourceView =vc.view;
    }
    [vc presentViewController:alertController animated:YES completion:nil];
}



//+ (void)kidRequst:(UIViewController *)vc andTheDatas:(NSMutableDictionary *)dic
//{
//    [JPUSHService resetBadge];
//    [JPUSHService setBadge:0];
//    NSArray *arr = [[NSArray alloc] initWithObjects:Base@"user.do?action=sendMessageToParent", nil];
//    [[MBProgressHUD showHUDAddedTo:vc.view animated:YES] setUserInteractionEnabled:NO];;
//
//
//    [[GetCode shareManager] getRequstTheURL:arr andTheDatas:dic withTheAuth:[UserManager modelManager].authCode andTheViewController:vc refreshHeadler:^(int index) {
//        
//    } completionHeadler:^{
//        [MBProgressHUD hideAllHUDsForView:vc.view  animated:YES];
//        NSDictionary *dic = [GetCode shareManager].getJson[@(0)];
//        NSString *code = [NSString stringWithFormat:@"%@",dic[@"code"]];
//        if ([code isEqualToString:@"1000"]) {
//            
//            [MBProgressHUD showError:klocalizeString(localRequstFromParent) toView:vc.view ];
//            
//        }
//        else{
//            
//            [UserManager parentSeleted:dic[@"msg"] VC:vc andWho:@"child" andTheMessage:klocalizeString(localErrorReason) ];
//        }
//        
//    }];
//}


- (NSMutableArray *)jieXiDiQu:(NSString *)key andTheNSArray:(NSArray *)arr andTheId:(NSInteger)termType
{
    _arrDatas = [[NSMutableArray alloc] init];
    [arr enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx,BOOL *_Nonnull stop){
        if ([[obj valueForKey:key] integerValue] == termType) {
            [_arrDatas addObject:obj];
            
        }
        
        
    }];
    return _arrDatas;
}

- (NSMutableDictionary *)clearTheNull:(NSDictionary *)dic
{
   
    
        NSMutableDictionary *sls = [[NSMutableDictionary alloc] initWithDictionary:dic];
        for (id key in [sls allKeys]) {
            
            if ([[sls valueForKey:key] isKindOfClass:[NSNull class]] ) {
                [sls setObject:@"" forKey:key];
                
            }
            
        }
        
   

    return sls;
   
}
@end
